<?php
class Help{
    protected $main_table = 'data_help';
	protected $main_id = 'help_id';
	protected $db = null;
	
	public function __construct($db){
		$this->db=$db;
	}
   
	public function __destruct(){
		unset($this->db);
	}
	public function get_table_name(){
	    return $this->main_table;
	    
	}
	
	public function insert_data($data){
		if(!is_array($data))
		my_jump('輸入的參數有誤');
		$rows = $this->db->insert($this->main_table, $data);
		$insert_id = $this->db->getInsertId();
		return $insert_id;	
	}

	public function update_data($data,$where){
		if(!is_array($data))
		my_jump('輸入的參數有誤');
		$result = $this->db->update($this->main_table,$data,$where);
		return $result;
	}	

	public function del_data($where){
		$result = $this->db->delete($this->main_table,$where);
		return $result;
	}	

	public function get_data_row($id,$field='*'){
		if(!intval($id))
		my_jump('輸入的參數有誤!');
		$sql = "SELECT ".$field." FROM ".$this->main_table." WHERE ".$this->main_id."='".intval($id)."' ";
		$data = $this->db->getRow($sql);
		return $data;
	}	

	public function get_data_array($where,$order='help_id DESC',$limit='10',$field='*'){
		$sql = "SELECT ".$field." FROM ".$this->main_table." WHERE ".$where." ORDER BY ".$order;
		if(intval($limit)){
			$sql .= " LIMIT ".$limit;
		}
		$data = $this->db->getAll($sql);
		return $data;
	} 

	public function get_data_list(){
		global $cf_info_var;
		
		$sql = "SELECT help_id,help_title,help_sort FROM ".$this->main_table;
		$data = $this->db->getAll($sql);
		//dump($data);
		$item = array();
		$retnru = array();
		
		foreach($cf_info_var['help']['help_sort'] as $k=>$v){
			$item['title'] = $v;
			$item['id'] = $k;
			$list = array();
			foreach($data as $vv){
				if($vv['help_sort']==$k){
					$list[] = $vv;	
				}
				
			}
			$item['list'] = $list;
			$return[] = $item;
		}
		return $return;
	}

}
?>